package com.fxu.mq.api;

import cn.hutool.core.collection.CollUtil;
import com.fxu.framework.core.base.Result;
import com.fxu.framework.core.util.MapUtil;
import com.fxu.mq.producer.RedisStreamsSender;
import com.fxu.mq.producer.RedisSimpleProducer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.stream.RecordId;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/***
 * <p>fxu</p>
 * 测试MQ的API接口
 * @author fangxu
 * @version 2022-07-07
 ***/
@Slf4j
@RestController
@RequestMapping("/mqApi")
@Api(tags = "Redis MQ Test")
@RequiredArgsConstructor
public class RedisMqTestController {
	private final RedisSimpleProducer smsProducer;
	private final RedisStreamsSender streamsSender;
	public static String STREAMS_KEY = "streamKey";

	@PostMapping("/testSimple")
	@ApiOperation("发布消息1")
	public Result<String> testSimple(@RequestParam Long id, @RequestParam String mobile, @RequestParam Long channelId) {
		smsProducer.sendSmsSendMessage(id, mobile, channelId, "1122",
				CollUtil.toList(MapUtil.of("1", "2")));
		return Result.ok("成功");
	}

	@PostMapping("/testStreams")
	@ApiOperation("发布消息2")
	public Result<RecordId> testStreams(@RequestParam String message) {
		return Result.ok(streamsSender.sendSmsSendMessage(STREAMS_KEY, MapUtil.of("message", message)));
	}

}